<?php
class Settings extends Admin_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->library('Form_validation');

	}
	
	public function index()
	{
		$data['group_date'] = $this->setting->group_date;
		$this->load->view('setting', $data);
	}
	
	public function setting($group = 'site')
	{
		$loads = $this->setting->group($group);
		$data['loads'] = $loads ? $loads : array();

        foreach ($data['loads'] as $rules)
        {
            $this->form_validation->set_rules($rules->key, $rules->key, 'trim|xss_clean');
        }

		if ($this->form_validation->run())
		{
			foreach ($data['loads'] as $rules)
			{
				$this->setting->edit($rules->key,$this->form_validation->set_value($rules->key));
	        }
			$this->_jui_message('操作成功');
		}
		else
		{
			$this->load->view('setting_open', $data);
		}
	}

	public function add()
	{
		$val = $this->form_validation;
		$val->set_rules('keyname', 'keyname', 'trim|xss_clean');
		$val->set_rules('key', 'key', 'trim|xss_clean');
		$val->set_rules('value', 'value', 'trim|xss_clean');
		$val->set_rules('group', 'group', 'trim|xss_clean');
		$val->set_rules('autoload', 'autoload', 'trim|xss_clean');
		$val->set_rules('content', 'content', 'trim|xss_clean');

		if ($val->run())
		{
			$this->setting->insert($val->set_value('keyname'), $val->set_value('key'), $val->set_value('value'), $val->set_value('group'), $val->set_value('autoload'), $val->set_value('content'));
			$this->_jui_message('操作成功');
		}
		else
		{
			$data['group_date'] = $this->setting->group_date;
			$this->load->view('setting_edit', $data);
		}
	}
}

/* End of file settings.php */
/* Location: ./application/controllers/manage/settings.php */